package ua.eug.robov2.schematic.chips;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import ua.eug.robov2.schematic.wire.Wire;

public class Pin implements Externalizable {
	public int chip; // chip index on schematic
	public int wire; // wire (index) connected to pin
	public int num; // pin number
	public Boolean state;
	
	// input - false, output - true
	public Boolean mode;
	
	// virtual pin for wires without driver
	public static Pin Float = new Pin();
	
	public Pin() {
		state = false;
		mode = false;
	}
	
	public Pin(int c, int n) {
		this();
		chip = c;
		num = n;
	}

	@Override
	public void readExternal(ObjectInput in) throws IOException,
			ClassNotFoundException {
		chip = in.readInt();
		num = in.readByte();	
		if (num>32) {
			mode = true;
			num -= 32;
		}
	}

	@Override
	public void writeExternal(ObjectOutput out) throws IOException {
		out.writeInt(chip);
		int p = (mode)?32:0;
		out.writeByte(p+num);
	}
	
}
